﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using XPathAutoSuggest.ViewModels;

namespace XPathAutoSuggest {
    /// <summary>
    /// Class allows user to click a hyperlink and launch the browser with the CommandParameter
    /// </summary>
    public class GoLinksCommand : CommandBase {
        /// <summary>
        /// Constructor remembers the ViewModel instance so it can be called for Execute and CanExecute
        /// </summary>
        /// <param name="newView"></param>
        public GoLinksCommand(IXPathToolVm newView) : base(newView) { }
        #region ICommand Members

        /// <summary>
        /// Controls whether the command is enabled
        /// </summary>
        /// <param name="parameter">Not used</param>
        /// <returns>Whatever the ModelView says</returns>
        public override bool CanExecute(object parameter) {
            return ((HelpLinks_ViewModel)_MV).GoLinksCommandCanExecute();
        }

        /// <summary>
        /// Passes execution to the ModelView for implementation
        /// </summary>
        /// <param name="parameter">The URL to open</param>
        public override void Execute(object parameter) {
            base.Execute(parameter);
            ((HelpLinks_ViewModel)_MV).GoLinksCommandExecute((string)parameter);
        }
        #endregion
    }

    /// <summary>
    /// Fires when user wants to close the view
    /// </summary>
    public class CloseLinksCommand : CommandBase {
        /// <summary>
        /// Constructor remembers the ViewModel instance so it can be called for Execute and CanExecute
        /// </summary>
        public CloseLinksCommand(IXPathToolVm newView) : base(newView) { }

        /// <summary>
        /// Determines whether the command can fire
        /// </summary>
        /// <param name="parameter">Not used</param>
        /// <returns>True if the command can fire, otherwise false</returns>
        public override  bool CanExecute(object parameter) {
            return ((HelpLinks_ViewModel)_MV).CloseLinksCommandCanExecute();
        }

        /// <summary>
        /// Does the actual work
        /// </summary>
        /// <param name="parameter">Not used</param>
        public override void Execute(object parameter) {
            base.Execute(parameter);
            ((HelpLinks_ViewModel)_MV).CloseLinksCommandExecute();
        }
    }
}
